<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>我</title>
    <link rel="stylesheet" href="__WECHAT__/css/style.css">
    <link href="__WECHAT__/css/mui.picker.min.css" rel="stylesheet" />
    <link href="__WECHAT__/css/mui.poppicker.css" rel="stylesheet" />
    <script src="__WECHAT__/js/jquery.min.js"></script>
    <script src="__WECHAT__/js/public.js"></script>
    <script src="__WECHAT__/js/mui.min.js"></script>
    <link rel="stylesheet" href="__WECHAT__/css/mui.min.css">
    <script src="__WECHAT__/js/mui.picker.js"></script>
    <script src="__WECHAT__/js/mui.poppicker.js"></script>
    <script src="__WECHAT__/js/city.data-3.js" type="text/javascript" charset="utf-8"></script>
</head>
<body style="background: #f6f6f6">
<div class="wo_con">
    <header class="header_con" id="member_bj">
        <h1 style="margin-top: 0px;">我的</h1>
        <img src="{$user.headpic}" style="width:60px; height:60px; border-radius:50%;-webkit-border-radius:50%;-moz-border-radius:50%;"/>
        <div class="yhm">{$user.nickname}</div>
    </header>
    <div class="jrwm_con">
        <div class="dh_box">
            <form class="form">
                <ul>
                    <li>
                        <label> </label> 姓名：
                        <div class="float_r">
                            <input type="text" class="username" placeholder="请输入姓名" value="{$user.username}" style="border: 0;width: 180px;margin-bottom:0px;">
                        </div>
                    </li>
                    <li>
                        <label> </label> 联系方式：
                        <div class="float_r">
                            <input type="text" class="phone" placeholder="请输入联系方式" value="{$user.phone}" style="border: 0;width: 180px;margin-bottom:0px;">
                        </div>
                    </li>
                    <li>
                        <label> </label> 所在地区：
                        <div class="float_r">
                            <input type="text" id='showCityPicker3' class="region" placeholder="请选择所在地区" value="{$user.region}" style="border: 0;width: 180px;margin-bottom:0px;">
                        </div>
                    </li>
                    <li>
                        <label> </label> 详细地址：
                        <div class="float_r">
                            <input type="text" class="address" placeholder="请输入详细地址" value="{$user.address}" style="border: 0;width: 180px;margin-bottom:0px;">
                        </div>
                    </li>
                </ul>
                <div class="xd_box">
                    <a class="sjxd save-info"> 保存</a>
                    <div class="clear"></div>
                </div>
            </form>
        </div>
    </div>
    <div class="clear"></div>
</div>
</body>
<script src="__WECHAT__/vendors/layer/layer.js"></script>
<script>
    (function($, doc) {
        $.init();
        $.ready(function() {
            /**
             * 获取对象属性的值
             * 主要用于过滤三级联动中，可能出现的最低级的数据不存在的情况，实际开发中需要注意这一点；
             * @param {Object} obj 对象
             * @param {String} param 属性名
             */
            var _getParam = function(obj, param) {
                return obj[param] || '';
            };

            //-----------------------------------------
            /*****三级联动*****/

            var cityPicker3 = new $.PopPicker({
                layer: 3
            });
            cityPicker3.setData(cityData3);
            var showCityPickerButton = doc.getElementById('showCityPicker3');
            var cityResult3 = doc.getElementsByClassName('region');
            showCityPickerButton.addEventListener('tap', function(event) {
                cityPicker3.show(function(items) {
                    var region = _getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text');
                    cityResult3[0].value = region;
                });
            }, false);
        });
    })(mui, document);
</script>
<script>
    var edit_user_url = '{:url('wechat/User/edit')}';
    var index_user_url = '{:url('wechat/User/index')}';

    $('.save-info').click(function () {
       var username = $('.username').val();
       var phone = $('.phone').val();
       var region = $('.region').val();
       var address = $('.address').val();
       $.post(edit_user_url,{
           'username':username,
           'phone':phone,
           'region':region,
           'address':address,
       },function (result) {
           if (result.code == 200){
               layer.open({
                   content:result.message,
                   skin: 'msg',
                   time: 2,
                   end: function(elem){
                       window.location.href = index_user_url;
                   }
               });
           }else{
               layer.open({
                   content:result.message,
                   skin: 'msg',
                   time: 2
               });
           }
       })
    });
</script>
</html>